#include<bits/stdc++.h>
#define int long long
#define N 400005
using namespace std;
int T;
int s1[N],s2[N];
set<int> s;
void sol(){
	int x;
	scanf("%lld",&x);
	if(*s.lower_bound(x)==x) s.erase(x);
	else s.insert(x);
	if(!s.size()){
		printf("0\n");
		return;
	} 
	int cnt=0,ans=0;
	for(int i:s) cnt++,s1[cnt]=s2[cnt]=i;
	reverse(s2+1,s2+cnt+1);
	for(int i=1;i<=cnt;i++) s1[i]+=s1[i-1],s2[i]+=s2[i-1];
	ans=s1[cnt]-s1[1];
	for(int i=2;i<=cnt;i++) ans-=max(0ll,s1[i]-s2[i-1]);
	printf("%lld\n",ans);
}
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	srand(time(0));
	scanf("%lld",&T);
	while(T--) sol();
	return 0;
}
